import PureProviderList from '../components/provider-list';
import {fetchProviderListByService} from 'actions/service';
import { getFetchStatus } from 'actions/util';
import * as ReactRedux from 'react-redux';
import * as React from 'react';

const mapStateToProps = (state) => {
  return {
    isFetching: getFetchStatus(state, fetchProviderListByService),
    providerList: state.providerListByService
  };
};

const mapDispatchToProps = (dispatch) => {
  return {
    initFetch: (serviceId) => {
      dispatch(fetchProviderListByService(serviceId));
    }
  };
};

class ProviderList extends React.Component {

  componentDidMount() {
    this.props.initFetch(this.props.serviceId);
  }

  render() {
    return <PureProviderList {...this.props}/>;
  }
}

export default ReactRedux.connect(mapStateToProps, mapDispatchToProps)(ProviderList);
